package cn.yangliu.work;

import cn.yangliu.enums.PayStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.Date;

public class NotifyWorkHandler {


    private static final Logger logger = LoggerFactory.getLogger(NotifyWorkHandler.class);

    private String orderNo;
    private String payOrderNo;
    private PayStatusEnum status;
    private Date payTime;
    private BigDecimal payAmount;

    public NotifyWorkHandler(String orderNo, String payOrderNo, BigDecimal payAmount, PayStatusEnum status, Date payTime) {
        this.orderNo = orderNo;
        this.payOrderNo = payOrderNo;
        this.status = status;
        this.payTime = payTime;
        this.payAmount = payAmount;
    }

    public void doWork(UpdateWorker updateWorker, UpdateErrorCallBack errorCallBack, BusinessWorker... workers) {
        try {
            updateWorker.toDo(orderNo, payOrderNo, payAmount, status, payTime);
            for (BusinessWorker worker : workers) {
                worker.toDo(orderNo, payOrderNo,payAmount, status, payTime);
            }
        }catch (Exception e){
            logger.error(e.getMessage(),e);
            if (errorCallBack!=null){
                errorCallBack.todo(e,orderNo,payOrderNo,payAmount,status,payTime,workers);
            }
        }
    }
}
